package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.PageBaseRequest;
import com.example.saiweisi.model.VipKind;
import com.example.saiweisi.service.interf.IVipKindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/vipkind")
@RestController
@CrossOrigin
@Slf4j
public class VipKindController {
    @Autowired
    private IVipKindService vipKindService;
    //分页查询所有会员种类
    @GetMapping("/page")
    public Result page(PageBaseRequest pageBaseRequest) {
        return Result.success(vipKindService.page(pageBaseRequest));
    }
    //查所有会员种类
    @GetMapping("/getall")
    public Result getAll(){
        return Result.success(vipKindService.getAll());
    }
    //添加会员种类
    @PostMapping("/add")
    public Result addvipkind(@RequestBody VipKind vipKind){
        vipKindService.addvipkind(vipKind);
        return Result.success();
    }
    //删除会员种类
    @DeleteMapping("/delete{vipKindId}")
    public Result deleteviplind(@PathVariable Integer vipKindId){
        System.out.println(vipKindId);
        vipKindService.deletevipkind(vipKindId);
        return Result.success();
    }
    //批量删除
    @PostMapping("/deletes")
    public Result deletesviplind(@RequestBody List<Integer> vipKindIds){
        vipKindService.deletesvipkind(vipKindIds);
        return Result.success();
    }
    //根据id查找会员种类信息并返回前端，作为修改表单数据携带
    @GetMapping("/{vipKindId}")
    public Result getById(@PathVariable Integer vipKindId){
        VipKind vipKind=vipKindService.getById(vipKindId);
        return Result.success(vipKind);
    }
    @PutMapping("/update")
    public Result updatevipkind(@RequestBody VipKind vipKind){
        vipKindService.updatevipkind(vipKind);
        return Result.success();
    }
}
